﻿@page "/system_manager/attachment"
<div>
    <PageContainer Title="">
        <Breadcrumb>
            <Breadcrumb>
                <BreadcrumbItem>系统管理</BreadcrumbItem>
                <BreadcrumbItem>附件管理</BreadcrumbItem>
            </Breadcrumb>
        </Breadcrumb>
        <ChildContent>
            <Table @ref="_table"
                   TItem="AttachmentDto"
                   DataSource="@_datas"
                   Total="_total"
                   OnChange="@OnChange"
                   @bind-PageIndex="searchInput.PageIndex"
                   @bind-PageSize="searchInput.PageSize"
                   @bind-SelectedRows="_selectedRows"
                   Loading="@_tableIsLoading"
                   Context="model">
                <TitleTemplate>
                    <Row>
                        <AntDesign.Col Span="8">
                            <ResourceAuthorize ResourceKey="system_manager_attachment_delete_selected">
                                <Button Type="@ButtonType.Primary" Icon="delete" Danger OnClick="OnDeletesClick">
                                    删除选中
                                </Button>
                            </ResourceAuthorize>
                        </AntDesign.Col>
                        <AntDesign.Col Span="16" Style="text-align:right">
                            <Space>
                                <ResourceAuthorize ResourceKey="system_manager_attachment_refresh">
                                    <SpaceItem>
                                        <Button Type="@ButtonType.Primary" Icon="reload" OnClick="OnReLoadTable">
                                            刷新
                                        </Button>
                                    </SpaceItem>
                                </ResourceAuthorize>
                            </Space>
                        </AntDesign.Col>
                    </Row>

                </TitleTemplate>
                <RowTemplate>
                    <ResourceAuthorize ResourceKey="system_manager_attachment_delete_selected">
                        <Selection Key="@(model.Id.ToString())" />
                    </ResourceAuthorize>
                    <Column Title="编号" @bind-Field="@model.Id" />
                    <Column Title="业务类型" @bind-Field="@model.BusinessType">
                        <Tag>@EnumExtension.GetEnumDescription(model.BusinessType)</Tag>
                    </Column>
                    <Column Title="业务编号" @bind-Field="@model.BusinessId" />
                    <Column Title="类型" Field="@model.FileType">
                        <Tag>@EnumExtension.GetEnumDescription(model.FileType)</Tag> @model.ContentType
                    </Column>
                    <Column Title="大小" Field="@model.Size">
                        @model.Size B
                    </Column>
                    <Column Title="目录" @bind-Field="@model.Path"  />
                    <Column Title="名称" @bind-Field="@model.Name"  />
                    <Column Title="后缀" @bind-Field="@model.Suffix"  />
                    <Column Title="原始名称" @bind-Field="@model.OriginalName" Style="max-width:200px"  />
                    <Column Title="文件" @bind-Field="@model.Url">

                        @if (model.FileType.Equals(AttachmentFileType.Image))
                        {

                            if (model.BusinessType.Equals(AttachmentBusinessType.Avatar))
                            {
                                <Avatar Size="64" Src="@model.Url" />
                            }
                            else
                            {

                                <img src="@model.Url" width="100" height="100" />
                            }
                        }
                        else 
                        {
                            <a href="@model.Url" target="_blank">@model.OriginalName</a>
                        }

                    </Column>
                    <Column Title="创建时间" @bind-Field="@model.CreatedTime" Format="@SystemConstant.DateTimeFormat" Sortable />
                    <ActionColumn>
                        <Space>
                            <ResourceAuthorize ResourceKey="system_manager_attachment_delete">
                                <SpaceItem><Button Type="@ButtonType.Primary" Danger OnClick="()=>OnDeleteClick(model.Id)">删除</Button></SpaceItem>
                            </ResourceAuthorize>
                        </Space>
                    </ActionColumn>
                </RowTemplate>
            </Table>
        </ChildContent>
    </PageContainer>
</div>